package com.chixing.day12_date_factory.homework;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class Customer {

    public static void main(String[] args) throws ParseException {
        MyOrder order = new MyOrder();
        MyOrder order1 = new  MyOrder(1,12,33f,"2022-08-01","smith");
        MyOrder order2 = new MyOrder(2,122,323f,"2022-05-01","smith");
        MyOrder order3 = new MyOrder(3,121,334f,"2022-04-01","smith");
        MyOrder order4 = new MyOrder(4,121,334f,"2021-09-01","billy");
        ArrayList<MyOrder> orders= new ArrayList<MyOrder>();
          orders.add(order1);
          orders.add(order2);
          orders.add(order3);
          orders.add(order4);
        int sum= 0;
        for (int i = 0; i <orders.size(); i++) {
            if (orders.get(i).getOrderCustomer().equals("smith")){
                sum += orders.get(i).getOrderPrice();
            }
        }
        System.out.println(sum);


        for (int j = 0; j <orders.size(); j++) {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date date = format.parse("2022-5-1");
            Date date1 = format.parse(orders.get(j).getLocalDateTime());

            if (date1.before(date)) {
                System.out.println(orders.get(j));
            }

        }

    }

}
